import { reqGoodsList } from "@/api";

const state = {
    searchInfo:{},  //请求过来的数据都放到这里面
};
const mutations = {
    SET_SEARCHINFO(state,searchInfo){
        state.searchInfo = searchInfo
    }
};
const actions = {
    async getSearchInfoHandler({commit},searchParams){
        try {
            let result = await reqGoodsList(searchParams);
            if(result && result.code == 200){
                commit('SET_SEARCHINFO',result.data)
            }
        } catch (error) {
            console.error(error);
            return Promise.reject(error)
        }   
    }
};
const getters = {
    attrsList(state){
        return state.searchInfo.attrsList || [];
    },
    trademarkList(state){
        return state.searchInfo.trademarkList || [];
    },
    goodsList(state){
        return state.searchInfo.goodsList || [];
    },
    total(state){
        return state.searchInfo.total || 0;
    }
};

export default {
  namespaced: true, //开启命名空间
  state,
  mutations,
  actions,
  getters,
};
